﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BitTorrentSharp.Peers
{
	/// <summary>
	/// Represent as a non-keep-alive message send between peers.
	/// </summary>
	public abstract class PeerNonKeepAliveMessage : PeerMessage
	{
		/// <summary>
		/// When ovrrided by a derived class, it is used to get the type of the message.
		/// </summary>
		public abstract PeerMessageType Type
		{
			get;
		}

		/// <summary>
		/// When ovrrided by a derived class, it is used to get the payload bytes of this message.
		/// </summary>
		/// <remarks>If this message has no data, this method will return a empty array.</remarks>
		/// <returns>The byte sequence of this message. The result does not contain the type signature.</returns>
		protected abstract byte[] GetPayloadBytes();

		/// <summary>
		/// Get all the bytes of this message.
		/// </summary>
		/// <returns>The byte sequence of this message.</returns>
		protected override byte[] GetBytesCore()
		{
			return ByteHelper.Concat(BitConverter.GetBytes((int)this.Type).EnsureBigEndian(), this.GetPayloadBytes());
		}
	}
}
